# ----------------------
# client.py  
# ----------------------
from tasks import add_numbers 
import time

def main():
    print("发送任务...")
    # 异步调用（非阻塞）
    async_result = add_numbers.delay(4, 5)
    
    # 显示任务ID
    print(f"任务ID: {async_result.id}")
    print("可以使用以下命令监控任务状态：")
    print(f"python monitor.py {async_result.id}\n")
    
    # 获取结果（阻塞等待，超时30秒）
    try:
        # 等待任务完成
        while not async_result.ready():
            print("等待任务完成...")
            time.sleep(1)
            
        result = async_result.get(timeout=30)
        print(f"计算结果: {result}")
    except Exception as e:
        print(f"任务执行失败: {str(e)}")
 
if __name__ == "__main__":
    main()